// EDMatrix3d.cpp: implementation of the EDMatrix3d class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "EDMatrix3d.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

EDMatrix3d::EDMatrix3d()
{/*
	m_mtr[0][0].m_strExpression = _T ( "1" );
	m_mtr[0][1].m_strExpression = _T ( "0" );
	m_mtr[0][2].m_strExpression = _T ( "0" );
	m_mtr[0][3].m_strExpression = _T ( "0" );
	
	m_mtr[1][0].m_strExpression = _T ( "0" );
	m_mtr[1][1].m_strExpression = _T ( "1" );
	m_mtr[1][2].m_strExpression = _T ( "0" );
	m_mtr[1][3].m_strExpression = _T ( "0" );
	
	m_mtr[2][0].m_strExpression = _T ( "0" );
	m_mtr[2][1].m_strExpression = _T ( "0" );
	m_mtr[2][2].m_strExpression = _T ( "1" );
	m_mtr[2][3].m_strExpression = _T ( "0" );
	
	m_mtr[3][0].m_strExpression = _T ( "0" );
	m_mtr[3][1].m_strExpression = _T ( "0" );
	m_mtr[3][2].m_strExpression = _T ( "0" );
	m_mtr[3][3].m_strExpression = _T ( "1" );*/
}

EDMatrix3d::~EDMatrix3d()
{

}

EDMatrix3d& EDMatrix3d::operator = ( const EDMatrix3d& mtr )
{
	for ( int i = 0; i < 4; i++ )
	{
		for ( int j = 0; j < 4; j++ )
		{
			m_mtr[i][j] = mtr.m_mtr[i][j];
		}
	}
	return *this;
}

EDSQLExpression& EDMatrix3d::operator () ( const int iRow, const int iCol )
{
	return m_mtr[iRow][iCol];
}

void EDMatrix3d::SetFromGe ( const AcGeMatrix3d& mtr )
{
	for ( int i = 0; i < 4; i++ )
	{
		for ( int j = 0; j < 4; j++ )
		{
			this->m_mtr[i][j].m_strExpression.Format ( _T ( "%f" ), mtr ( i, j ) );
		}
	}
}

void EDMatrix3d::SetToGe ( AcGeMatrix3d& mtr )
{
	for ( int i = 0; i < 4; i++ )
	{
		for ( int j = 0; j < 4; j++ )
		{
			mtr(i,j) = atof ( (LPCTSTR)m_mtr[i][j].m_strExpression );
		}
	}
}

void EDMatrix3d::CopyFrom ( const EDSQLExpression exp[4][4] )
{
	for ( int i = 0; i < 4; i++ )
	{
		for ( int j = 0; j < 4; j++ )
		{
			this->m_mtr[i][j] = exp[i][j];
		}
	}
}

void EDMatrix3d::Clear()
{
	for ( int i = 0; i < 4; i++ )
	{
		for ( int j = 0; j < 4; j++ )
		{
			this->m_mtr[i][j].m_strExpression.Empty();
		}
	}
}

void EDMatrix3d::SetToIdentity()
{
	m_mtr[0][0].m_strExpression = _T ( "1" );
	m_mtr[0][1].m_strExpression = _T ( "0" );
	m_mtr[0][2].m_strExpression = _T ( "0" );
	m_mtr[0][3].m_strExpression = _T ( "0" );
	
	m_mtr[1][0].m_strExpression = _T ( "0" );
	m_mtr[1][1].m_strExpression = _T ( "1" );
	m_mtr[1][2].m_strExpression = _T ( "0" );
	m_mtr[1][3].m_strExpression = _T ( "0" );
	
	m_mtr[2][0].m_strExpression = _T ( "0" );
	m_mtr[2][1].m_strExpression = _T ( "0" );
	m_mtr[2][2].m_strExpression = _T ( "1" );
	m_mtr[2][3].m_strExpression = _T ( "0" );
	
	m_mtr[3][0].m_strExpression = _T ( "0" );
	m_mtr[3][1].m_strExpression = _T ( "0" );
	m_mtr[3][2].m_strExpression = _T ( "0" );
	m_mtr[3][3].m_strExpression = _T ( "1" );
}

BOOL EDMatrix3d::IsSingleDigital()
{
	for ( int i = 0; i < 4; i++ )
	{
		for ( int j = 0; j < 4; j++ )
		{
			if ( EDSQLExpression::IsSingleDigitalVar ( &m_mtr[i][j] ) == FALSE )
				return FALSE;
		}
	}
	return TRUE;
}

void EDMatrix3d::VX ( const AcGeVector3d& v )
{
	m_mtr[0][0].m_strExpression.Format ( _T ( "%f" ), v.x );
	m_mtr[1][0].m_strExpression.Format ( _T ( "%f" ), v.y );
	m_mtr[2][0].m_strExpression.Format ( _T ( "%f" ), v.z );
}

void EDMatrix3d::VX ( const EDVector3d& v )
{
	m_mtr[0][0] = v.x;
	m_mtr[1][0] = v.y;
	m_mtr[2][0] = v.z;
}

void EDMatrix3d::VX ( const EDSQLExpression exp[3] )
{
	m_mtr[0][0] = exp[0];
	m_mtr[1][0] = exp[1];
	m_mtr[2][0] = exp[2];
}

void EDMatrix3d::VX ( const EDSQLExpression exp0, const EDSQLExpression exp1, const EDSQLExpression exp2 )
{
	m_mtr[0][0] = exp0;
	m_mtr[1][0] = exp1;
	m_mtr[2][0] = exp2;
}

AcGeVector3d EDMatrix3d::VX()
{
	AcGeVector3d v;
	v.set (
		atof ( (LPCTSTR)m_mtr[0][0].m_strExpression ),
		atof ( (LPCTSTR)m_mtr[1][0].m_strExpression ),
		atof ( (LPCTSTR)m_mtr[2][0].m_strExpression ) );
	return v;
}

void EDMatrix3d::VY ( const AcGeVector3d& v )
{
	m_mtr[0][1].m_strExpression.Format ( _T ( "%f" ), v.x );
	m_mtr[1][1].m_strExpression.Format ( _T ( "%f" ), v.y );
	m_mtr[2][1].m_strExpression.Format ( _T ( "%f" ), v.z );
}

void EDMatrix3d::VY ( const EDVector3d& v )
{
	m_mtr[0][1] = v.x;
	m_mtr[1][1] = v.y;
	m_mtr[2][1] = v.z;
}

void EDMatrix3d::VY ( const EDSQLExpression exp[3] )
{
	m_mtr[0][1] = exp[0];
	m_mtr[1][1] = exp[1];
	m_mtr[2][1] = exp[2];
}

void EDMatrix3d::VY ( const EDSQLExpression exp0, const EDSQLExpression exp1, const EDSQLExpression exp2 )
{
	m_mtr[0][1] = exp0;
	m_mtr[1][1] = exp1;
	m_mtr[2][1] = exp2;
}

AcGeVector3d EDMatrix3d::VY()
{
	AcGeVector3d v;
	v.set (
		atof ( (LPCTSTR)m_mtr[0][1].m_strExpression ),
		atof ( (LPCTSTR)m_mtr[1][1].m_strExpression ),
		atof ( (LPCTSTR)m_mtr[2][1].m_strExpression ) );
	return v;
}

void EDMatrix3d::VZ ( const AcGeVector3d& v )
{
	m_mtr[0][2].m_strExpression.Format ( _T ( "%f" ), v.x );
	m_mtr[1][2].m_strExpression.Format ( _T ( "%f" ), v.y );
	m_mtr[2][2].m_strExpression.Format ( _T ( "%f" ), v.z );
}

void EDMatrix3d::VZ ( const EDVector3d& v )
{
	m_mtr[0][2] = v.x;
	m_mtr[1][2] = v.y;
	m_mtr[2][2] = v.z;
}

void EDMatrix3d::VZ ( const EDSQLExpression exp[3] )
{
	m_mtr[0][2] = exp[0];
	m_mtr[1][2] = exp[1];
	m_mtr[2][2] = exp[2];
}

void EDMatrix3d::VZ ( const EDSQLExpression exp0, const EDSQLExpression exp1, const EDSQLExpression exp2 )
{
	m_mtr[0][2] = exp0;
	m_mtr[1][2] = exp1;
	m_mtr[2][2] = exp2;
}

AcGeVector3d EDMatrix3d::VZ()
{
	AcGeVector3d v;
	v.set (
		atof ( (LPCTSTR)m_mtr[0][2].m_strExpression ),
		atof ( (LPCTSTR)m_mtr[1][2].m_strExpression ),
		atof ( (LPCTSTR)m_mtr[2][2].m_strExpression ) );
	return v;
}

void EDMatrix3d::PT ( const AcGePoint3d& v )
{
	m_mtr[0][3].m_strExpression.Format ( _T ( "%f" ), v.x );
	m_mtr[1][3].m_strExpression.Format ( _T ( "%f" ), v.y );
	m_mtr[2][3].m_strExpression.Format ( _T ( "%f" ), v.z );
}

void EDMatrix3d::PT ( const EDPoint3d& v )
{
	m_mtr[0][3] = v.x;
	m_mtr[1][3] = v.y;
	m_mtr[2][3] = v.z;
}

void EDMatrix3d::PT ( const EDSQLExpression exp[3] )
{
	m_mtr[0][3] = exp[0];
	m_mtr[1][3] = exp[1];
	m_mtr[2][3] = exp[2];
}

void EDMatrix3d::PT ( const EDSQLExpression exp0, const EDSQLExpression exp1, const EDSQLExpression exp2 )
{
	m_mtr[0][3] = exp0;
	m_mtr[1][3] = exp1;
	m_mtr[2][3] = exp2;
}

AcGePoint3d EDMatrix3d::PT()
{
	AcGePoint3d v;
	v.set (
		atof ( (LPCTSTR)m_mtr[0][3].m_strExpression ),
		atof ( (LPCTSTR)m_mtr[1][3].m_strExpression ),
		atof ( (LPCTSTR)m_mtr[2][3].m_strExpression ) );
	return v;
}

void EDMatrix3d::Replace ( const CVarArray* pVarAr, const int nStart )
{
	for ( int i = 0; i < 4; i++ )
	{
		for ( int j = 0; j < 4; j++ )
		{
			EDSQLExpression::Replace ( &m_mtr[i][j], pVarAr, nStart );
		}
	}
}
